<template>
  <div class="app-container">
    <div v-if="!MyOrdering && !AllOrdering">
      <Find :OriginalFilter="{ static: true }" :formList="formList" @findClicked="findClicked" />
      <div>
        <el-card style="margin-top: 15px" shadow="never" :body-style="{ padding: '15px' }">
          <div slot="header">
            <span style="font-weight: 600">待订购明细</span>
          </div>
          <Table
            :isLoading="isLoading1"
            @selectList="selectList"
            @inputChange="inputChange"
            :tableHeader="tableHeader"
            :tableData="PendingOrderInquiryTableDate"
            selection
            :TableHeight="98"
          ></Table>
          <PageModule :PageData="{ buttonS: true, total: totalList }" @pageChange="pageChange1" @pageSizeChange="pageSizeChange1" />
        </el-card>
      </div>
    </div>

    <div v-if="MyOrdering">
      <Find :OriginalFilter="{ static: true }" @clickNumber1="clickNumber" @Launchform="Launchform5" @findClicked="findData" :formList="formList2" />
      <Find
        :searchImg="false"
        :OriginalFilter="{ static: true }"
        @clickNumber1="clickNumber"
        @Launchform="Launchform11"
        @findClicked="findData"
        :formList="formList5"
      />
      <el-card style="margin-top: 15px" shadow="never" :body-style="{ padding: '13px' }">
        <div style="display: flex">
          <div style="width: 72%" slot="header" class="f16 mb18">
            <span style="font-weight: 600">我的订购单</span>
            <Table
              :isLoading="isLoading2"
              @selectList="selectList1"
              @currentRow1="clicktogetdata3"
              @currentRow="clicktogetdata"
              class="table"
              @inputChange="inputChange1"
              :tableHeader="tableHeader2"
              :tableData="AllSlipDateQueryListTableDate"
              selection
              :TableHeight="80"
            >
            </Table>

            <PageModule :PageData="{ buttonS: true, total: totalL }" @pageChange="pageChangeL" @pageSizeChange="pageSizeChangeL" />
          </div>

          <div style="margin-left: 15px; width: 38%" class="flex main">
            <div slot="header" class="f16 mb18">
              <span style="font-weight: 600">指令明细</span>
              <Table :isLoading="isLoading2" :tableHeader="tableHeader3" :tableData="tableDatElIST" selection :TableHeight="80"></Table>
            </div>

            <div style="margin-left: 15px; width: 70%" slot="header" class="f16 mb18">
              <span style="font-weight: 600">分码明细</span>
              <Table :isLoading="isLoading4" :tableHeader="tableHeader4" :tableData="tableData4" selection :TableHeight="80"></Table>
            </div>
          </div>
        </div>
        <div style="display: flex; flex-wrap: wrap; width: 83%">
          <p style="margin-top: 10px">
            <span class="mr10">材料名称</span>
            <el-input
              :disabled="true"
              v-model="inputValue.mtlName"
              class="mr55"
              placeholder=""
              size="small"
              clearable
              @change=""
              style="width: 300px; height: 80px"
            />
          </p>
          <span style="margin-right: 10px; margin-top: 10px; height: 25px">物料编码</span>
          <el-input
            :disabled="true"
            v-model="inputValue.mtlNo"
            placeholder=""
            size="small"
            clearable
            @change=""
            style="width: 120px; height: 30px; margin-top: 10px"
          />

          <span style="margin-right: 10px; margin-top: 10px; margin-left: 10px; height: 25px">请购单号</span>
          <el-input
            :disabled="true"
            v-model="inputValue.reqNo"
            placeholder=""
            size="small"
            clearable
            @change=""
            style="width: 100px; height: 30px; margin-top: 10px"
          />

          <span style="margin-right: 10px; margin-top: 10px; margin-left: 10px; height: 25px">请购部</span>
          <el-input
            :disabled="true"
            v-model="inputValue.reqDeptName"
            placeholder=""
            size="small"
            clearable
            @change=""
            style="width: 100px; height: 30px; margin-top: 10px"
          />

          <span style="margin-right: 10px; margin-top: 10px; margin-left: 10px; height: 25px">请购日期</span>
          <el-input
            :disabled="true"
            v-model="inputValue.reqDate"
            placeholder=""
            size="small"
            clearable
            @change=""
            style="width: 100px; height: 30px; margin-top: 10px"
          />

          <span style="margin-right: 10px; margin-top: 10px; margin-left: 10px; height: 25px">需求日期</span>
          <el-input
            :disabled="true"
            v-model="inputValue.reqRta"
            placeholder=""
            size="small"
            clearable
            @change=""
            style="width: 100px; height: 30px; margin-top: 10px"
          />

          <p style="margin-left: 430px; margin-top: -25px">
            <span style="margin-right: 10px">请购备注</span>
            <el-input
              :disabled="true"
              v-model="inputValue.reqMemo"
              placeholder=""
              size="small"
              clearable
              @change=""
              style="width: 600px; height: 30px"
            />

            <span style="margin-right: 10px; margin-left: 35px">取消数量</span>
            <el-input
              :disabled="true"
              v-model="inputValue.cancelQty"
              placeholder=""
              size="small"
              clearable
              @change=""
              style="width: 100px; height: 30px"
            />
          </p>
        </div>
      </el-card>
    </div>

    <div v-if="AllOrdering">
      <Find
        :OriginalFilter="{ static: true }"
        @clickNumber1="clickNumber5"
        @Launchform="Launchform6"
        :formList="formList3"
        @findClicked="findClicked1"
      />
      <div class="flex mt10 main">
        <el-card shadow="never" :body-style="{ padding: '13px' }">
          <div slot="header" class="f16 mb18">
            <span style="font-weight: 600">所有订购单</span>
          </div>
          <Table
            :isLoading="isLoading5"
            @currentRow="clicktogetdata2"
            :tableHeader="tableHeader5"
            :tableData="AllSlipDateQueryTableDate"
            :TableHeight="95"
          ></Table>
          <PageModule :PageData="{ buttonS: true, total }" @pageChange="pageChange" @pageSizeChange="pageSizeChange" />
        </el-card>
        <el-card shadow="never" :body-style="{ padding: '13px' }">
          <div slot="header" class="f16 mb18">
            <span style="font-weight: 600">指令明细</span>
          </div>
          <Table :isLoading="isLoading6" :tableHeader="tableHeader6" :tableData="InstructionDetailTableDate" :TableHeight="95"></Table>
        </el-card>
      </div>
    </div>

    <el-dialog v-model="dialogVisible6" width="50%" class="dialog pb0">
      <Find :OriginalFilter="{ static: true }" @findClicked="findData7" @Launchform="Launchform7" :searchImg="false" :formList="formList7" />

      <Table
        :isLoading="isLoading7"
        selection
        @selectList="selectListA"
        class="divNitive"
        :tableHeader="tableHeader1"
        :tableData="GeneralMaterialsQueryTableDate"
        :TableHeight="47"
        :outTableHeight="90"
      />
      <PageModule :PageData="{ buttonS: true, total: total1 }" @pageChange="pageChange11" @pageSizeChange="pageSizeChange11" />
    </el-dialog>
  </div>
</template>
<script lang="ts">
import { defineComponent, ref, onMounted } from 'vue'
import JMessage from '@/utils/JMessage'
export default defineComponent({
  name: 'MinorPurchase'
})
</script>
<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
import { ManufacturerQuery } from '@/api/PurchasingDepartment/FactoryPurchasing/MaterialRequisition'
import {
  FormAPurchaseOrder,
  deleteGenerateOrderInformation,
  PendingOrderInquiry,
  GenerateOrderInformation,
  GeneralMaterialsQuery,
  AddGeneralMaterials,
  AllSlipDateQuery,
  InstructionDetail,
  AllSlipDateQueryList,
  BatchReturn
} from '@/api/PurchasingDepartment/FactoryPurchasing/MinorPurchase'
import { classifyQuery, VendorQuery } from '@/api/WarehouseDepartment/FactoryStorage/FitOutsourcingProcessing'
import fileRequest from '@/utils/fileRequest'
import LoginWork from '@/utils/LoginWork'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
// 批量退回
const BatchReturnParms = ref([])

const BatchReturnMethods = async () => {
  try {
    const result = await BatchReturn(BatchReturnParms.value)
    if (result.code === 200) {
      BatchReturnParms.value = []
      AllSlipDateQueryListMethods()
      ElMessage.success(result.message)
    } else {
      ElMessage.error(result.message)
    }
  } catch (error) {
    ElMessage.error('退回失败')
  }
}

const handleCloseMateriaLKlc = (_done?: () => void) => {
  if (BatchReturnParms.value.length === 0) {
    JMessage.warning('请勾选需要退回的数据')
  } else {
    ElMessageBox.confirm('确认要退回吗?')
      .then(async () => {
        BatchReturnMethods()
      })
      .catch(() => {})
  }
}

const isLoading1 = ref(true)
const isLoading2 = ref(true)
const isLoading4 = ref(false)
const isLoading5 = ref(true)
const isLoading6 = ref(true)
const isLoading7 = ref(true)

const inputValue = ref<any>({
  mtlName: '',
  mtlNo: '',
  reqNo: '',
  reqDeptName: '',
  reqDate: '',
  reqRta: '',
  reqMemo: '',
  cancelQty: ''
})

// 形成订购单
const FormAPurchaseParms = ref({
  request: [],
  requiredDate: '',
  vendorName: '',
  vendorNo: ''
})

const selectList1 = (row: any) => {
  FormAPurchaseParms.value.request = row.map((item: any) => {
    return item
  })
  BatchReturnParms.value = row.map((item: any) => {
    return item
  })
}

const FormAPurchaseOrderMethods = async () => {
  const result = await FormAPurchaseOrder(FormAPurchaseParms.value)
  if (result.code === 200) {
    AllSlipDateQueryListMethods()
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

// 回显

const AllSlipDateQueryListTableDateParmsList = ref('')
const clicktogetdata = (row: any) => {
  tableDatElIST.value = []
  tableDatElIST.value.push({ qty: row.qty, list: row.style })
  inputValue.value = row
  AllSlipDateQueryListTableDateParmsList.value = row.purNo
}

const clicktogetdata3 = (row: any) => {
  row.vendorNo = vendorLis.value.split(' ')[0]
  row.vendorName = vendorLis.value.split(' ')[1]
  inputChange1(row)
}

const vendorLis = ref<any>('')

const tableDatElIST = ref<any>([])

// 我的订购单查询
const AllSlipDateQueryListTableDate = ref<any>([])

const AllSlipDateQueryListTableDateParms = ref({
  companyId: '',
  lotDetail: '',
  pageNum: 1,
  pageSize: 40,
  purDateEnd: '',
  purDateStart: '',
  purFlag: 0,
  purNo: '',
  purType: '',
  sysUser: '',
  typeNo: '',
  vendorNo: '',
  reqNo: ''
})

const inputChange1 = async (row: any) => {
  const result = await LoginWork.post<any, any>(`/SporadicClearanceOperation/updatePurchaseOrder`, [row])
  if (result.code === 200) {
    AllSlipDateQueryListMethods()
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const clickNumber = (count: any) => {
  switch (count) {
    case '0': {
      AllSlipDateQueryListTableDateParms.value.purFlag = 0
      break
    }
    case '1': {
      AllSlipDateQueryListTableDateParms.value.purFlag = 1
      break
    }
    case '2': {
      AllSlipDateQueryListTableDateParms.value.purFlag = 2
      break
    }
  }
  AllSlipDateQueryListMethods()
}

const Launchform5 = (row: any) => {
  AllSlipDateQueryListTableDateParms.value.purNo = row[1].inputValue
  AllSlipDateQueryListTableDateParms.value.reqNo = row[0].inputValue
  AllSlipDateQueryListTableDateParms.value.typeNo = row[2].selectValue.split(' ')[0]
  AllSlipDateQueryListTableDateParms.value.vendorNo = row[3].selectValue.split(' ')[0]
  AllSlipDateQueryListTableDateParms.value.purDateStart = row[4].dateValue[0]
  AllSlipDateQueryListTableDateParms.value.purDateEnd = row[4].dateValue[1]
  AllSlipDateQueryListMethods()
  vendorLis.value = row[10].selectValue

  // FormAPurchaseParms.value.vendorName = row[0].selectValue.split(' ')[1]
  // FormAPurchaseParms.value.vendorNo = row[0].selectValue.split(' ')[0]
  // FormAPurchaseParms.value.requiredDate = row[1].dateValue
}

const Launchform11 = (row: any) => {
  vendorLis.value = row[0].selectValue

  FormAPurchaseParms.value.vendorName = row[0].selectValue.split(' ')[1]
  FormAPurchaseParms.value.vendorNo = row[0].selectValue.split(' ')[0]
  FormAPurchaseParms.value.requiredDate = row[1].dateValue
}

const AllSlipDateQueryListMethods = async () => {
  tableDatElIST.value = []
  const result = await AllSlipDateQueryList(AllSlipDateQueryListTableDateParms.value)
  AllSlipDateQueryListTableDate.value = result.lotNoList.map((item: any) => {
    if (item.purNo !== null) {
      item.disable = true
    }
    item.change = 'Y'
    item.disableConfirm = true
    return item
  })
  if (result.lotNoList.length !== 0) {
    inputValue.value = result.lotNoList[0]
    tableDatElIST.value.push({ qty: result.lotNoList[0].qty, list: result.lotNoList[0].style })
    // console.log(inputValue.value)
  }
  totalL.value = result.total
  isLoading2.value = false
}

const totalL = ref(0)

const pageChangeL = (val: any) => {
  AllSlipDateQueryListTableDateParms.value.pageNum = val
  AllSlipDateQueryListMethods()
}

const pageSizeChangeL = (val: any) => {
  AllSlipDateQueryListTableDateParms.value.pageSize = val
  AllSlipDateQueryListMethods()
}

const claerInputValueAndSelectValue2 = () => {
  formList3.value.forEach((item) => {
    if (item.type === 'input') {
      item.inputValue = ''
    }
    if (item.type === 'select') {
      item.selectValue = ''
    }
    if (item.type === 'date') {
      item.dateValue = ''
    }
  })
}

const claerInputValueAndSelectValue = () => {
  formList2.value.forEach((item) => {
    if (item.type === 'input') {
      item.inputValue = ''
    }
    if (item.type === 'select') {
      item.selectValue = ''
    }
    if (item.type === 'date') {
      item.dateValue = ''
    }
  })
}

// 指令明细查询
const InstructionDetailParms = ref({
  companyId: '',
  lotDetail: '',
  pageNum: '',
  pageSize: '',
  purDateEnd: '',
  purDateStart: '',
  purFlag: '',
  purNo: '',
  purType: '',
  sysUser: '',
  typeNo: '',
  vendorNo: '',
  mtlNo: '',
  reqNo: ''
})

// 厂商获取
const VendorQueryMethods = async () => {
  let NewArray = []
  const result = await ManufacturerQuery()
  NewArray = result.reduce((arr: any, item: any) => {
    if (item.vendorNo && item.vendorName) {
      // 只添加非空的 typeName 和 typeNo
      arr.push(item.vendorNo + ' ' + item.vendorName)
    }
    return arr
  }, [])
  formList3.value[3].selectOptions = EvaluatesTheArrayReturnValue(NewArray)

  formList2.value[3].selectOptions = EvaluatesTheArrayReturnValue(NewArray)
  formList5.value[0].selectOptions = EvaluatesTheArrayReturnValue(NewArray)
}

const EvaluatesTheArrayReturnValue = (ArrayList: any) => {
  return ArrayList.map((item: any, index: any) => {
    return {
      optionKey: index,
      optionValue: item,
      optionLabel: item
    }
  })
}

const classifyQueryMethods = async () => {
  let NewArray = []
  const result = await classifyQuery()
  NewArray = result.reduce((arr: any, item: any) => {
    if (item.typeNo && item.typeName) {
      // 只添加非空的 typeName 和 typeNo
      arr.push(item.typeNo + ' ' + item.typeName)
    }
    return arr
  }, [])
  formList3.value[2].selectOptions = EvaluatesTheArrayReturnValue(NewArray)
  formList2.value[2].selectOptions = EvaluatesTheArrayReturnValue(NewArray)
}

const clicktogetdata2 = (row: any) => {
  InstructionDetailParms.value.companyId = row.companyId
  InstructionDetailParms.value.sysUser = row.sysUser
  InstructionDetailParms.value.mtlNo = row.mtlNo
  InstructionDetailParms.value.reqNo = row.reqNo
  InstructionDetailParms.value.purType = row.purType
  AllSlipDateQueryListTableDateParmsList1.value = row.purNo
  InstructionDetailMethods()
}

const InstructionDetailTableDate = ref([])

const InstructionDetailMethods = async () => {
  const result = await InstructionDetail(InstructionDetailParms.value)
  InstructionDetailTableDate.value = result.lotNoList
  isLoading6.value = false
}

// 所有订购单查询
const AllSlipDateQueryParms = ref({
  companyId: '',
  lotDetail: '',
  pageNum: 1,
  pageSize: 40,
  purDateEnd: '',
  purDateStart: '',
  purNo: '',
  purType: '',
  sysUser: '',
  typeNo: '',
  vendorNo: '',
  purFlag: 2
})

const clickNumber5 = (count: any) => {
  switch (count) {
    case '0': {
      AllSlipDateQueryParms.value.purFlag = 0
      break
    }
    case '1': {
      AllSlipDateQueryParms.value.purFlag = 1
      break
    }
    case '2': {
      AllSlipDateQueryParms.value.purFlag = 2
      break
    }
  }
  AllSlipDateQueryMethods()
}

const Launchform6 = (row: any) => {
  AllSlipDateQueryParms.value.purNo = row[0].inputValue
  AllSlipDateQueryParms.value.lotDetail = row[1].inputValue
  AllSlipDateQueryParms.value.typeNo = row[2].selectValue.split(' ')[0]
  AllSlipDateQueryParms.value.vendorNo = row[3].selectValue.split(' ')[0]
  AllSlipDateQueryParms.value.purDateEnd = row[4].dateValue[1]
  AllSlipDateQueryParms.value.purDateStart = row[4].dateValue[0]

  AllSlipDateQueryMethods()
}

const AllSlipDateQueryTableDate = ref([])

const AllSlipDateQueryMethods = async () => {
  const result = await AllSlipDateQuery(AllSlipDateQueryParms.value)
  AllSlipDateQueryTableDate.value = result.lotNoList
  if (result.lotNoList.length > 0) {
    InstructionDetailParms.value.companyId = result.lotNoList[0].companyId
    InstructionDetailParms.value.sysUser = result.lotNoList[0].sysUser
    InstructionDetailParms.value.mtlNo = result.lotNoList[0].mtlNo
    InstructionDetailParms.value.reqNo = result.lotNoList[0].reqNo
    InstructionDetailParms.value.purType = result.lotNoList[0].purType
    InstructionDetailMethods()
  }
  total.value = result.total
  isLoading5.value = false
}

const total = ref(0)

const pageChange = (val: any) => {
  AllSlipDateQueryParms.value.pageNum = val
  AllSlipDateQueryMethods()
}

const pageSizeChange = (val: any) => {
  AllSlipDateQueryParms.value.pageSize = val
  AllSlipDateQueryMethods()
}

const findData = async (count: string) => {
  if (count === '批量退回') {
    handleCloseMateriaLKlc()
  }
  if (count === '返回') {
    MyOrdering.value = false
  }
  if (count === '置空') {
    claerInputValueAndSelectValue()
  }
  if (count === '形成订购单') {
    if (FormAPurchaseParms.value.request.length === 0) {
      JMessage.warning('请选择需要形成订购单的数据')
    } else if (FormAPurchaseParms.value.vendorNo === '') {
      JMessage.warning('厂商不可为空')
    } else if (FormAPurchaseParms.value.requiredDate === '') {
      JMessage.warning('日期不可为空')
    } else {
      FormAPurchaseOrderMethods()
    }
  }
  if (count === '导出订购单') {
    if (AllSlipDateQueryListTableDateParmsList.value === '' || AllSlipDateQueryListTableDateParmsList.value === null) {
      JMessage.warning('请点击需要导出的订购单号')
    } else {
      const res = (await fileRequest.get(
        `/SporadicClearanceOperation/exportMyPurchaseOrder?purNo=${AllSlipDateQueryListTableDateParmsList.value}`
      )) as any
      const link = document.createElement('a') // 利用a标签自定义下载文件名
      let blob = new Blob([res.data]) // 创建Blob对象，设置文件类型
      link.style.display = 'none'
      //设置连接
      link.href = window.URL.createObjectURL(blob)
      const FileName = decodeURI(res.headers['content-disposition'].split(`filename=`)[1])
      link.download = FileName //自定义文件名字
      document.body.appendChild(link)
      //模拟点击事件
      link.click()
      document.body.removeChild(link)
    }
  }
}

const AllSlipDateQueryListTableDateParmsList1 = ref('')

const findClicked1 = async (count: string) => {
  if (count === '返回') {
    AllOrdering.value = false
  }
  if (count === '置空') {
    claerInputValueAndSelectValue2()
  }
  if (count === '打印订购单') {
    if (AllSlipDateQueryListTableDateParmsList1.value === '' || AllSlipDateQueryListTableDateParmsList1.value === null) {
      JMessage.warning('请点击需要导出的订购单号')
    } else {
      const res = (await fileRequest.get(
        `/SporadicClearanceOperation/exportAllPurchaseOrder?purNo=${AllSlipDateQueryListTableDateParmsList1.value}`
      )) as any
      const link = document.createElement('a') // 利用a标签自定义下载文件名
      let blob = new Blob([res.data]) // 创建Blob对象，设置文件类型
      link.style.display = 'none'
      //设置连接
      link.href = window.URL.createObjectURL(blob)
      const FileName = decodeURI(res.headers['content-disposition'].split(`filename=`)[1])
      link.download = FileName //自定义文件名字
      document.body.appendChild(link)
      //模拟点击事件
      link.click()
      document.body.removeChild(link)
    }
  }
}

// 新增
const AddGeneralMaterialsParms = ref<any>([])

const selectListA = (row: any) => {
  AddGeneralMaterialsParms.value = row.map((item: any) => {
    return item
  })
}

const AddGeneralMaterialsMethods = async () => {
  try {
    const result = await AddGeneralMaterials(AddGeneralMaterialsParms.value)
    if (result.code === 200) {
      PendingOrderInquiryMethods()
      AddGeneralMaterialsParms.value = []
      GeneralMaterialsQueryMethods()
      JMessage.success(result.message)
    } else {
      JMessage.error(result.message)
    }
  } catch (error) {
    GeneralMaterialsQueryMethods()
  }
}

const formList7 = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入材料名称',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入材料颜色',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'button',
    checkboxLabel: '待请购批处理'
  }
])

const findData7 = (row: any) => {
  if (row === '待请购批处理') {
    if (AddGeneralMaterialsParms.value.length === 0) {
      JMessage.warning('请选择需要请购的数据')
    } else {
      AddGeneralMaterialsMethods()
    }
  }
}

const Launchform7 = (row: any) => {
  GeneralMaterialsQueryParms.value.mtlColor = row[1].inputValue
  GeneralMaterialsQueryParms.value.mtlName = row[0].inputValue
  GeneralMaterialsQueryMethods()
}

const dialogVisible6 = ref(false)

// 选择通用材料查询
const GeneralMaterialsQueryParms = ref({
  mtlColor: '',
  mtlName: '',
  pageNum: 1,
  pageSize: 40,
  publicFlag: '0'
})

const GeneralMaterialsQueryTableDate = ref([])

const GeneralMaterialsQueryMethods = async () => {
  const result = await GeneralMaterialsQuery(GeneralMaterialsQueryParms.value)
  GeneralMaterialsQueryTableDate.value = result.lotNoList.map((item: any) => {
    if (item.flag === 'Y') {
      item.backgroundColor = 'red'
      item.change = null
    }
    return item
  })
  total1.value = result.total
  isLoading7.value = false
}

const total1 = ref(0)

const pageChange11 = (val: any) => {
  GeneralMaterialsQueryParms.value.pageNum = val
  GeneralMaterialsQueryMethods()
}

const pageSizeChange11 = (val: any) => {
  GeneralMaterialsQueryParms.value.pageSize = val
  GeneralMaterialsQueryMethods()
}

const selectList = (row: any) => {
  GenerateOrderInformationParms.value = row.map((item: any) => {
    return item
  })
  deleteGenerateOrderInformationParms.value = GenerateOrderInformationParms.value[GenerateOrderInformationParms.value.length - 1]
}

const totalList = ref(0)

const pageChange1 = (val: any) => {
  PendingOrderInquiryParms.value.pageNum = val
  PendingOrderInquiryMethods()
}

const pageSizeChange1 = (val: any) => {
  PendingOrderInquiryParms.value.pageSize = val
  PendingOrderInquiryMethods()
}

// 删除
const deleteGenerateOrderInformationParms = ref<any>()

const deleteGenerateOrderInformationMethods = async () => {
  const result = await deleteGenerateOrderInformation(GenerateOrderInformationParms.value[length])
  if (result.code === 200) {
    PendingOrderInquiryMethods()
    deleteGenerateOrderInformationParms.value = {}
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const handleCloseMateriaLKlc5 = () => {
  if (deleteGenerateOrderInformationParms.value === undefined) {
    JMessage.warning('请选择需要删除的数据')
  } else {
    ElMessageBox.confirm('确认要删除数据吗?')
      .then(async () => {
        deleteGenerateOrderInformationMethods()
      })
      .catch(() => {})
  }
}

const openFullScreen2 = () => {
  const loading = ElLoading.service({
    lock: true,
    text: '正在汇总请稍后',
    background: 'rgba(0, 0, 0, 0.7)'
  })
  return loading
}
const findClicked = (click: any) => {
  if (click === '进入我的订购单') {
    AllSlipDateQueryListMethods()
    MyOrdering.value = !MyOrdering.value
  }

  if (click === '进入所有订购单') {
    AllSlipDateQueryMethods()
    AllOrdering.value = !AllOrdering.value
  }
  if (click === '生成订购资料') {
    if (GenerateOrderInformationParms.value.length === 0) {
      JMessage.warning('请勾选需要生成订购的数据')
    } else {
      GenerateOrderInformationMethods()
    }
  }
  if (click === '删除') {
    handleCloseMateriaLKlc5()
  }
  if (click === '选择通用资料') {
    GeneralMaterialsQueryMethods()
    dialogVisible6.value = true
  }
}

// 生成订购资料
const GenerateOrderInformationParms = ref([])

const GenerateOrderInformationMethods = async () => {
  const result = await GenerateOrderInformation(GenerateOrderInformationParms.value)
  let active = openFullScreen2()
  if (result.code === 200) {
    active.close()
    PendingOrderInquiryMethods()
    GenerateOrderInformationParms.value = []
    JMessage.success(result.message)
  } else {
    active.close()
    JMessage.error(result.message)
  }
}

// 待定修改
const inputChange = async (row: any) => {
  if (row.qty !== '') {
    row.qty = Number(row.qty)
  }
  const result = await LoginWork.post<any, any>(`/SporadicClearanceOperation/updateNotOrderDetails`, [row])
  if (result.code === 200) {
    PendingOrderInquiryMethods()
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

// 待订购查询
const PendingOrderInquiryTableDate = ref([])

const PendingOrderInquiryParms = ref({
  pageNum: 1,
  pageSize: 40
})

const PendingOrderInquiryMethods = async () => {
  const result = await PendingOrderInquiry(PendingOrderInquiryParms.value.pageNum, PendingOrderInquiryParms.value.pageSize)
  PendingOrderInquiryTableDate.value = result.lotNoList.map((item: any) => {
    item.change = 'Y'
    item.disableConfirm = true
    return item
  })
  totalList.value = result.total
  isLoading1.value = false
}

onMounted(() => {
  PendingOrderInquiryMethods()

  VendorQueryMethods()

  classifyQueryMethods()
})

const MyOrdering = ref(false)
const AllOrdering = ref(false)
const formList = ref([
  {
    type: 'button',
    checkboxLabel: '选择差异资料',
    disabled: true
  },
  {
    type: 'button',
    checkboxLabel: '选择通用资料'
  },
  {
    type: 'button',
    checkboxLabel: '生成订购资料'
  },
  {
    type: 'button',
    checkboxLabel: '进入我的订购单'
  },
  {
    type: 'button',
    checkboxLabel: '进入所有订购单'
  },
  {
    type: 'button',
    checkboxLabel: '删除'
  }
])
const tableHeader = ref([
  {
    label: '类型',
    prop: 'slipType',
    change: true
  },
  {
    label: '指令',
    prop: 'lotNo',
    change: true
  },
  {
    label: '物料编码',
    prop: 'mtlNo',
    change: true
  },
  {
    label: '材料颜色',
    prop: 'mtlColor',
    change: true
  },
  {
    label: '材料名称',
    prop: 'mtlName',
    change: true
  },
  {
    label: '规格',
    prop: 'mtlSpec',
    change: true
  },
  {
    label: '单位',
    prop: 'mtlUnit',
    change: true
  },
  {
    label: '数量',
    prop: 'qty'
  },
  {
    label: '备注',
    prop: 'remark'
  }
])

const tableHeader1 = ref([
  {
    label: '物料编码',
    prop: 'mtlNo',
    backgroundColor: true
  },
  {
    label: '颜色',
    prop: 'mtlColor'
  },
  {
    label: '材料名称',
    prop: 'mtlName'
  },
  {
    label: '规格',
    prop: 'mtlSpec'
  },
  {
    label: '单位',
    prop: 'mtlUnit'
  },
  {
    label: '库存量',
    prop: 'stkQty'
  },
  {
    label: '安全量',
    prop: 'safetyQty'
  }
])

const formList2 = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入请购单号',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入订单号',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '分类',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '厂商',
    selectLabel: '',
    selectOptions: []
  },

  {
    type: 'date',
    dateLabel: '订购日期',
    dateValue: ''
  },
  {
    type: 'radio1',
    checkboxLabel: '未确认',
    checked: false,
    label: '1'
  },
  {
    type: 'radio1',
    checkboxLabel: '已确认',
    checked: false,
    label: '2'
  },
  {
    type: 'radio1',
    checkboxLabel: '全部',
    checked: false,
    label: '0'
  },
  {
    type: 'button',
    checkboxLabel: '形成订购单'
  },
  {
    type: 'button',
    checkboxLabel: '导出订购单'
  }
])

const formList5 = ref([
  {
    type: 'select',
    selectValue: '',
    selectP: '厂商',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'dateSingle',
    dateLabel: '需求日期',
    dateValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '返回'
  },
  {
    type: 'button',
    checkboxLabel: '批量退回'
  }
])
const tableHeader2 = ref([
  {
    label: '类别',
    prop: 'purType',
    change: true
  },
  {
    label: '指令号',
    prop: 'purLot',
    disable: true
  },
  {
    label: '分类名称',
    prop: 'typeName',
    change: true
  },
  {
    label: '材料颜色',
    prop: 'mtlColor',
    change: true
  },
  {
    label: '材料名称',
    prop: 'mtlName',
    change: true
  },
  {
    label: '规格',
    prop: 'mtlSpec',
    change: true
  },
  {
    label: '单位',
    prop: 'mtlUnit',
    change: true
  },
  {
    label: '订购单号',
    prop: 'purNo',
    change: true
  },
  {
    label: '订购日期',
    prop: 'purDate',
    change: true
  },
  {
    label: '请购量',
    prop: 'qty',
    change: true
  },
  {
    label: '预加量',
    prop: 'overQty',
    disable: true
  },
  {
    label: '多购量',
    prop: 'minusQty'
  },
  {
    label: '订购数量',
    prop: 'purQty',
    change: true
  },
  {
    label: '厂商代码',
    prop: 'vendorNo',
    change: true
  },
  {
    label: '厂商名称',
    prop: 'vendorName',
    change: true
  },
  {
    label: '厂商回复日期',
    prop: 'inDate',
    disable: true
  },
  {
    label: '需求交期',
    prop: 'vendorDate'
  },
  {
    label: '采购备注',
    prop: 'purMemo',
    disable: true
  }
])

const tableHeader3 = ref([
  {
    label: '货号',
    prop: 'list'
  },
  {
    label: '数量',
    prop: 'qty'
  }
])

const tableHeader4 = ref([
  {
    label: '号码',
    prop: 'type'
  },
  {
    label: '数量',
    prop: 'type'
  }
])
const tableData4 = ref([
  {
    type: '123'
  }
])

const formList3 = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入订购号',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入指令号',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '分类',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '厂商',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'date',
    dateLabel: '订购日期',
    dateValue: ''
  },
  {
    type: 'radio1',
    checkboxLabel: '未下单',
    checked: false,
    label: '1'
  },
  {
    type: 'radio1',
    checkboxLabel: '已下单',
    checked: false,
    label: '2'
  },
  {
    type: 'radio1',
    checkboxLabel: '全部',
    checked: false,
    label: '0'
  },
  {
    type: 'button',
    checkboxLabel: '打印订购单'
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '返回'
  }
])
const tableHeader5 = ref([
  {
    label: '类型',
    prop: 'purType'
  },
  {
    label: '分类名称',
    prop: 'typeName'
  },
  {
    label: '材料颜色',
    prop: 'mtlColor'
  },
  {
    label: '材料名称',
    prop: 'mtlName'
  },
  {
    label: '规格',
    prop: 'mtlSpec'
  },
  {
    label: '订购单号',
    prop: 'purNo'
  },
  {
    label: '订购日期',
    prop: 'purDate'
  },
  {
    label: '请购量',
    prop: 'qty'
  },
  {
    label: '超买量',
    prop: 'overQty'
  },
  {
    label: '订购数量',
    prop: 'purQty'
  },
  {
    label: '厂商名称',
    prop: 'vendorName'
  },
  {
    label: '交期',
    prop: 'vendorDate'
  },
  {
    label: '送货方式',
    prop: 'sendType'
  },
  {
    label: '采购备注',
    prop: 'purMemo'
  },
  {
    label: '采购员',
    prop: 'sysUser'
  }
])

const tableHeader6 = ref([
  {
    label: '指令',
    prop: 'lotNo'
  },
  {
    label: '货号',
    prop: 'style'
  },
  {
    label: '数量',
    prop: 'qty'
  }
])
</script>

<style lang="less" scoped>
.main {
  width: 100%;
  background-color: white;
}

.btns {
  display: flex;
  padding: 10px 35px 5px;
  justify-content: end;

  .bg {
    background-color: #e7e7e7;
    border: 1px solid #e7e7e7;
    color: #000000;
  }
}

.table {
  :deep(th:nth-child(12)) {
    color: #0000ff !important;
  }

  :deep(th:nth-child(13)) {
    color: red !important;
  }

  :deep(th:nth-child(15)) {
    color: red !important;
  }

  :deep(th:nth-child(16)) {
    color: #0000ff !important;
  }
}
</style>
